package com.wawayaya.bookreader.jni;

import android.util.Log;

import java.io.File;

/**
 * audio转wav so lib加载
 */
public class Audio2Wav
{
	private static final String TAG = Audio2Wav.class.getSimpleName();
	private static final String LIB_NAME = "cklrd_soft_audio2wav";
	private static int s_nLoad = -1;
	
	public static final int CONVERT_OPTION_MUSIC = 0x00;
	public static final int CONVERT_OPTION_SPEECH = 0x01;
	public static final int CONVERT_OPTION_FASTMODE = 0x02;
	public static final int CONVERT_OPTION_DETECTBPM = 0x04;
	public static final int CONVERT_OPTION_NOANTIALIAS = 0x08;
	
	public static boolean initialize(String strPath) {
		if (s_nLoad >= 0)
			return (s_nLoad != 0);
		try {
			boolean bExist = false;
			String strFile = "";
			if (strPath != null && strPath.length() > 0) {
				strFile = strPath + "/lib" + LIB_NAME + ".so";
				File f = new File(strFile);
				bExist = f.exists();
			}
			if (bExist)
				System.load(strFile);
			else
				System.loadLibrary(LIB_NAME);
			s_nLoad = 1;
		} catch(UnsatisfiedLinkError e) {
			s_nLoad = 0;
			Log.d(TAG, e.getMessage());
		}
		return (s_nLoad != 0);
    }
	
	public static native int MpegDecode(String sFileIn, String sFileOut, int fWaveFile);
	public static native int Convert(String sFileIn, String sFileOut, int tempo, int pitch, int rate, int option);
	public static native String GetVersion();
};
